<?php
/*
 * page to display list of user's timesheets for selected year
*/
//check for an admin session
include("../inc_files/utils/checksession.php");
//include the page header
include("../inc_files/ui/header.php");?>
<title>My Timesheets</title>
<script
	type="text/javascript" src="../scripts/async.js"></script>
<script type="text/javascript">
//display the timesheet for the selected year
function processddl(){
	var ddl = document.getElementById("tsperiodyear");
	if(ddl.selectedIndex == 0){
		document.getElementById("datagrid").innerHTML = "";
	}  else {
		var yr = ddl.options[ddl.selectedIndex].value;
		refreshgrid(yr);
	}		
}

function createTimesheet(period){
	//post the data
	document.getElementById("datagrid").innerHTML = postasync("a_createtimesheet.php", "value", "period=" + period, false);
	processddl();	
}



//async refresh of tasks datagrid
function refreshgrid(yr){
	var nocache = Math.floor(Math.random() * 10000);
	getasync("a_mytimesheets.php?year=" + yr + "&amp;" + "nocache=" + nocache,"datagrid", true);		
}

</script>
</head>
<body>
	<?php //add the navigation to the page
include("../inc_files/ui/menu.php");?>

	<table style="width: 100%; align: center">
		<tr>
			<td style="width: 100%; font-size: 10pt; color: black;"
				align="center">Please select a year:&nbsp;&nbsp; <select
				name="tsperiodyear" id="tsperiodyear" onchange="processddl(this)">

					<option value="Please select...">Please select...</option>
					<?php
					//create drop down list options only for years which have timesheet periods created

					// Create connection
					include("../inc_files/utils/dbconnection.php");
					//query database
					$query ="SELECT DISTINCT LEFT(PeriodID,4) AS 'Year' FROM timesheet_periods;";
					$result = $mysqli->query( $query );
					//fill the array
					$year=0;
					while($row = mysqli_fetch_array($result))
					{
						$year = $row['Year'] ;
						echo "<option value=\"" . $year ."\">" . $year . "</option>";

					}

					$mysqli->close();
					?>
			</select>
			</td>
		</tr>
		<tr>

			<td align="center" style="position: relative; z-index: 1;">
				<!-- add a div tag to display the timesheets using AJAX -->
				<div id="datagrid"
					style="position: relative; z-index: 2; width: 600px; height: 600px; overflow-x: hidden; overflow-y: scroll; border: 1px solid #E0E0E0;"></div>
			</td>

		</tr>
	</table>
	<?php
	//add the page footer
	include("../inc_files/ui/footer.php");?>

</body>
</html>
